package edu.sctu.zhengsenwen.month201506.day20150623.operator;

/**
 * 逻辑操作符
 * Created by user15 on 2015/6/23.
 *
 */
public class LogicOperatorDemo {

    public static void main(String[] args) {

        final int VISIBLE = 1;
        final int DRAGGABLE = 2;
        final int EDITABLE = 4;
        final int COLORFUL = 8;

        int flags = 0;

        flags = flags | VISIBLE;
        flags = flags | DRAGGABLE;

        if((flags & VISIBLE) == VISIBLE){
            if((flags & DRAGGABLE) == DRAGGABLE){
                System.out.println("该旗子是可视并且可拖拉的");
            }
        }


        flags = flags | EDITABLE;
        if((flags & EDITABLE) == EDITABLE){
            System.out.println("该旗是可编辑的");
        }

        flags = flags | COLORFUL;
        if((flags & COLORFUL) == COLORFUL){
            System.out.println("该旗的颜色是可变的");
        }

        flags = flags ^ COLORFUL;
        if((flags & COLORFUL) != COLORFUL){
            System.out.println("该旗的颜色是不可变的");
        }


        if((flags & VISIBLE) == VISIBLE){
            if((flags & DRAGGABLE) == DRAGGABLE){
                if((flags & EDITABLE) == EDITABLE){
                    if((flags & COLORFUL) != COLORFUL){
                        System.out.println("该旗可视、可拖拉、可编辑但颜色不能改变");
                    }
                }
            }
        }
    }
}
